package com.enfo.zjabank.controller;

import com.alibaba.fastjson.JSONArray;
import com.enfo.zjabank.service.ChangeService;
import com.enfo.zjabank.tool.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zhoum on 2016/8/24.
 */
@Controller
@RequestMapping("/change")
public class ChangeController {
    @Autowired
    private ChangeService changeService;
    @RequestMapping(value = "/changeApply",method = RequestMethod.POST)
    public
    @ResponseBody
    String changeApply(@RequestBody List<Map<String,String>> form){
        if(form!=null && form.size()>0){
            try {
                changeService.changeApply(form);
            } catch (Exception e) {
                e.printStackTrace();
                return "fail";
            }
            return "success";
        }
        return "fail";
    }

    @RequestMapping(value = "/form",method = RequestMethod.POST)
    public @ResponseBody String form(HttpServletRequest request,HttpServletResponse response){
        System.out.println(request.getParameterMap());
        Map<String,String[]> map = request.getParameterMap();
        for(Map.Entry<String,String[]> entry:map.entrySet()){
            System.out.println(entry.getKey());
            System.out.println(entry.getValue()[0]);
        }
        return "success";
    }

    @RequestMapping(value = "/formB",method = RequestMethod.POST)
    public @ResponseBody String formB(@RequestBody List<Map<String,String>> list){
        System.out.printf(list.toString());
        return "success2";
    }
    @RequestMapping(value = "/formC",method = RequestMethod.POST)
    public @ResponseBody String formC(@RequestBody String json){
        System.out.printf(json);
        return "success2";
    }
}
